package com.ctesi.service.zhaobiao.henan;

import com.ctesi.utils.PutUtil;
import com.ctesi.utils.StringExtract;
import org.springframework.stereotype.Service;
import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.pipeline.Pipeline;
import us.codecraft.webmagic.processor.PageProcessor;

import java.security.PrivateKey;
import java.time.LocalDateTime;
@Service
public class HuNanProcessorService implements PageProcessor {
    private String bidType;
    @Override
    public void process(Page page) {

        //爬取内容逻辑
        System.out.println("----------开启爬取内容--------------");

        //招标主体信息
        String bidContext = page.getHtml().xpath("/html/body/div[12]/div[2]/div/div[3]").get();
        bidContext = StringExtract.removeEmptyLines(StringExtract.removeNbsp(StringExtract.removeTags(bidContext)));
        System.out.println(bidContext);
        //招标编号
        PutUtil.putField(page,bidContext,"招标项目编号：(.*?)\\s","bidId");

        //招标类型
        page.putField("bidType",bidType);

        //招标省份
        page.putField("bidProvince","广西省");

        //招标范围
        PutUtil.putField(page,bidContext,"招标范围：(.*?)建设规模","bidArange");

        //招标发布时间
        String bidPubTime = page.getHtml().xpath("/html/body/div[12]/div[2]/div/div[2]/text()").toString();
        System.out.println(bidPubTime);
        PutUtil.putField(page,bidPubTime,"(.*?)-(.*?)-(.*?)}","bidPubTime");

        //备注：没有该字段

        //数据创建时间
        LocalDateTime createTime = LocalDateTime.now();
        page.putField("createTime",createTime);

        //数据更新时间
        LocalDateTime updateTime = LocalDateTime.now();
        page.putField("updateTime",updateTime);

        //公告url
        page.putField("bidUrl",page.getUrl().get());

        //招标地区
        PutUtil.putField(page,bidContext,"建设地点：(.*?)\\n","bidArea");

        //投标人资格要求
        PutUtil.putField(page,bidContext,"投标人资格要求：(.*?)\\n","bidCredit");

        //评标办法
        PutUtil.putField(page,bidContext,"办法采用：(.*?)\\n","bidMethod");


        //招标状态：没有这个字段

        //招标人信息

        //招标机构
        PutUtil.putField(page,bidContext,"招标人：(.*?)\\n","bidUnity");

        //招标联系人
        PutUtil.putField(page,bidContext,"招标人：.*?\\n(.*?)\\n","bidName");

        //招标联系人电话
        PutUtil.putField(page,bidContext,"招标人：.*?\\n.*?电话:(.*?)\\n","bidPhone");

        //招标地址
        PutUtil.putField(page,bidContext,"招标人:.*?地址(.*?)\\n","bidAddress");

        //代理机构信息

        //代理机构
        PutUtil.putField(page,bidContext,"招标代理机构:(.*?)\\n","agencyUnity");

        //代理机构联系人
        PutUtil.putField(page,bidContext,"招标代理机构:.*?联系人:(.*?)\\n","agencyName");

        //代理机构联系人电话
        PutUtil.putField(page,bidContext,"招标代理机构:.*?电话:(.*?)\\n","agencyPhone");

        //代理机构地址
        PutUtil.putField(page,bidContext,"招标代理机构:.*?地址:(.*?)\\n","agencyAddress");

    }

    @Override
    public Site getSite() {
        return PageProcessor.super.getSite();
    }
}
